#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    ll n, q, cntA = 0,cntB = 0;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<pair<ll, ll>> a;
    for(int i = 0;i < s.size(); i++){
    	if(s[i] == 'B'){
    		cntB++;
    		if(cntA != 0)a.push_back({1, cntA});
    		a.push_back({2, 0});
    		cntA = 0;
    	}
    	else cntA++;
    }
    if(cntA != 0)a.push_back({1, cntA});

    ll mod = a.size();
    while(q--){
    	ll p, t = 0, cnt = 0;
    	cin >> p;
    	if(cntB){
    		while(p){
    			if(a[cnt % mod].first == 1){
    				ll diff = min(p, a[cnt % mod].second);
    				p -= diff;
    				t += diff;
    			}else{
    				p >>= 1;
    				t++;
    			}
    			cnt++;
    		}
    	}else{
    		t = p;
    	}
    	cout << t << '\n';
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}